{%- set scripts_dir = salt['pillar.get']('default:OMV_CRONSCRIPTS_DIR', '/var/lib/openmediavault/cron.d') -%}
{%- set userdefined_prefix = salt['pillar.get']('default:OMV_CRONTAB_USERDEFINED_PREFIX', 'userdefined-') -%}
{%- set separator = ' ' -%}
{{ pillar['headers']['multiline'] -}}
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user    command
{%- for job in jobs | selectattr('enable') %}
{% if job.execution == "exactly" -%}
{% if job.everynminute | to_bool %}*/{{ job.minute }}{% else %}{{ job.minute }}{% endif -%}
{{ separator }}{% if job.everynhour | to_bool %}*/{{ job.hour }}{% else %}{{ job.hour }}{% endif -%}
{{ separator }}{% if job.everyndayofmonth | to_bool %}*/{{ job.dayofmonth }}{% else %}{{ job.dayofmonth }}{% endif -%}
{{ separator }}{{ job.month }}{{ separator }}{{ job.dayofweek }}
{%- else -%}
@{{ job.execution }}
{%- endif -%}
{{ separator }}{{ job.username }}{{ separator }}{{ scripts_dir | path_join(userdefined_prefix ~ job.uuid) }}
{%- if not job.sendemail | to_bool -%}
{{ separator }}>/dev/null 2>&1
{%- else -%}
{{ separator }}2>&1 | mail -E -s "Cron{{ ' - ' ~ job.comment | replace('\n', ' ') if job.comment | length > 0 else '' }}" -a "From: Cron Daemon <{{ job.username }}>" {{ job.username }} >/dev/null 2>&1
{%- endif -%}
{%- endfor -%}
